<?php 
class Photos_model extends Model{

	function __construct (){
		parent::__construct();
	}

	public function get_all_photos ($userId) {
		$sql = "SELECT * FROM `photos` WHERE `UserId` = :UserId";
		$_array = array(
			"UserId"	=> $userId
		);

		return $this->db->select($sql,$_array);
	}

	public function get_all_albums ($userId) {
		$sql = "SELECT b.*,p.* FROM mediaalbums b INNER JOIN ( SELECT max(Id),AlbumsId,Name ImgName,Path ImgPath FROM photos GROUP BY AlbumsId) p ON p.AlbumsId =b.Id WHERE b.UserId = :UserId";
		$_array = array(
			"UserId"	=> $userId
		);
		$abc = $this->db->select($sql,$_array);
		return $abc;
	}

	public function all_photo_by_album_id ($albumsId) {
		$sql = "SELECT * FROM `photos` WHERE `AlbumsId` = :AlbumsId";
		$_array = array(
			"AlbumsId"	=> $albumsId
		);

		return $this->db->select($sql,$_array);
	}
}

